<template>
  <div class="app-container">

    <el-form :inline="true" class="demo-form-inline">

      <el-form-item>
        <el-input v-model="searchObj.orderId" placeholder="订单号"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="searchObj.userId" placeholder="用户id"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
        <el-button type="default" @click="resetData()">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- banner列表 -->
    <el-table v-loading="listLoading" :data="list"
              border
              fit
              highlight-current-row>

      <el-table-column prop="orderId" label="订单号" width="250"/>
      <el-table-column prop="userId" label="用户id" width="250"/>
      <el-table-column prop="userName" label="用户名" width="250"/>
      <el-table-column prop="shipping" label="发货地址" width="300"/>
      <el-table-column prop="receipt" label="收货地址" width="300"/>
      <el-table-column label="状态" width="80">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1">已发货</el-tag>
          <el-tag type="warning" v-if="scope.row.status == 2">已签收</el-tag>
          <el-tag type="success" v-if="scope.row.status == 3">已完成</el-tag>
          <el-tag type="info" v-if="scope.row.status == 4">已关闭</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini"  type="primary" @click="seleOrder(scope.row)">查看</el-button>
        </template>
      </el-table-column>

    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="fetchData"
      @size-change="changeSize"
    />

    <el-dialog
      title="订单详情"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose">

      <el-descriptions class="margin-top" title="订单详情" :column="3" :size="size" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-tickets"></i>
            订单号
          </template>
          {{order.orderId}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            用户名
          </template>
          {{order.userName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-location-outline"></i>
            收货地址
          </template>
          {{order.receipt}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i></i>
            订单状态
          </template>
          <el-tag v-if="order.status == 1" size="mini">已发货</el-tag>
          <el-tag v-if="order.status == 2" type="warning" size="mini">已签收</el-tag>
          <el-tag v-if="order.status == 3" type="success" size="mini">已完成</el-tag>
          <el-tag v-if="order.status == 4" type="info" size="mini">已关闭</el-tag>

        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-watch"></i>
            创建时间
          </template>
          {{order.createTime}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i></i>
            总价
          </template>
          {{order.total}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i></i>
            发货地址
          </template>
          {{order.shipping}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i></i>
            完成时间
          </template>
          <div v-if="order.finishTime != null">{{order.finishTime}}</div>
          <div v-if="order.finishTime == null">未完成</div>
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i></i>
            运单号
          </template>
          {{order.wbNO}}
        </el-descriptions-item>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building"></i>
            商品列表
          </template>
          <el-table
            border
            :data="order.goodsList"
            style="width: 100%">
            <el-table-column
              prop="goods.goodsName"
              label="商品名称"
              >
            </el-table-column>
            <el-table-column
              prop="goods.goodsPrice"
              label="单价"
              >
            </el-table-column>
            <el-table-column
              prop="num"
              label="数量">
            </el-table-column>
          </el-table>
        </el-descriptions-item>

      </el-descriptions>

    </el-dialog>

  </div>
</template>

<script>
export default {
  name: "processed-goods-order",
  data(){
    return{
      list: null, // 订单列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 5, // 每页记录数
      listLoading: true, // 数据是否正在加载
      searchObj: {
        orderId: null,
        userId: null,
        status: 9   //查询已处理订单,此处为一个标识，不代表查询的status为9
      },
      size: '',
      dialogVisible: false,
      order: {
        orderId: null,
        userName: null,
        receipt: null,
        status: null,
        createTime: null,
        goodsList: null,
        total: null
      },
    }

  },
  methods:{
    handleClose(done){
      this.$confirm('确认关闭？')
        .then(_ => {
          this.order = {}
          done();
        })
        .catch(_ => {});
    },
    fetchData(page = 1){
      this.page = page
      this.$http({
        url: this.$http.adornUrl(`/order/goods/list/${page}/${this.limit}`),
        method: 'get',
        params: this.searchObj
      }).then(({data}) => {
        this.list = data.data.records
        this.total = data.data.total
        this.listLoading = false
      })
    },
    // 重置查询表单
    resetData() {
      this.searchObj = {}
      this.searchObj.status=9
      this.fetchData()
    },
    // 页码切换
    changeSize(val) {
      this.limit = val
      this.page = 1
      this.fetchData(1)
    },
    seleOrder(order){
      this.order = order
      console.log(order)
      this.dialogVisible = true
    }
  },
  created() {
    this.fetchData()
  },
}
</script>

<style scoped>

</style>
